package org.zerta.troops.common;

import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;

public class Turn {
	
	Game game;
	Map <String, TurnData> turnDataMap;
	GameState gameState;
	private int turnCounter;
	
	public Turn( Game game, int turnCounter ) {
		this.game = game;
		turnDataMap = new HashMap <String, TurnData>();
		this.turnCounter = turnCounter;
	}
	
	public void addTurnData( TurnData turnData ) {
		Player p = turnData.getPlayer();
		
		if (turnDataMap.containsKey(p.getName().toLowerCase())) {
			turnDataMap.remove(p.getName().toLowerCase());
		}
		
		turnDataMap.put(p.getName().toLowerCase(), turnData);			
		
	}
	
	public Map<String, TurnData> getTurnDataList() {
		return turnDataMap;
	}
	
	public boolean allPlayersSubmitted() {
		Map <String, Player> players = game.getPlayers();
		
		String playerName;
		for (	Iterator <String> playerIterator = players.keySet().iterator(); 
				playerIterator.hasNext(); 
				) {
		
			playerName = playerIterator.next();
			
			if ( ! turnDataMap.containsKey(playerName.toLowerCase())) {
				return false;
			}
			
		}
		return true;
	}
	
	public Game getGame() {
		return game;
	}
	
	public void setGameState( GameState gameState ) {
		this.gameState = gameState;
	}
	
	public GameState getGameState() {
		return gameState;
	}

	public int getTurnCounter() {
		return turnCounter;
	}

}
